package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPunchTimeAddDTO;
import org.jsola.hr.dto.AttendPunchTimeUpdateDTO;
import org.jsola.hr.entity.AttendPunchTimeDO;
import org.jsola.hr.query.AttendPunchTimeQuery;
import org.jsola.hr.service.IAttendPunchTimeService;
import org.jsola.hr.vo.AttendPunchTimeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPunchTimeTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPunchTimeService attendPunchTimeService;

    /**
     * 生成add测试数据
     * @return AttendPunchTimeAddDTO
     */
    public AttendPunchTimeAddDTO getAttendPunchTimeAddDTO(){
        AttendPunchTimeAddDTO attendPunchTimeAddDTO = new AttendPunchTimeAddDTO();
        attendPunchTimeAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendPunchTimeAddDTO.setWorkWeekJson(getRandomValue("varchar",255));
        attendPunchTimeAddDTO.setPeriodJson(getRandomValue("varchar",1000));
        attendPunchTimeAddDTO.setIsAdvanc(SafeKit.getBoolean(getRandomValue("tinyint",0)));
        attendPunchTimeAddDTO.setIsAllowedLateEarly(SafeKit.getInteger(getRandomValue("tinyint",0)));
        attendPunchTimeAddDTO.setLateMinute(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchTimeAddDTO.setEarlyMinute(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchTimeAddDTO.setIsAllowLateLate(SafeKit.getInteger(getRandomValue("tinyint",0)));
        attendPunchTimeAddDTO.setOffWorkLateMinute(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchTimeAddDTO.setOnWorkLateMinute(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchTimeAddDTO.setEarliestPunchTime(getRandomValue("varchar",10));
        attendPunchTimeAddDTO.setLatestOnPunchTime(getRandomValue("varchar",10));
        attendPunchTimeAddDTO.setEarliestOffPunchTime(getRandomValue("varchar",10));
        attendPunchTimeAddDTO.setLatestPunchTime(getRandomValue("varchar",10));
        attendPunchTimeAddDTO.setAfterWorkNeedPunch(SafeKit.getInteger(getRandomValue("tinyint",0)));
        attendPunchTimeAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendPunchTimeAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPunchTimeUpdateDTO
     */
    public AttendPunchTimeUpdateDTO getAttendPunchTimeUpdateDTO(AttendPunchTimeVO attendPunchTimeVO){
        return attendPunchTimeService.selectDOById(attendPunchTimeVO.getId(), SITE_ID).to(AttendPunchTimeUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPunchTimeQuery
     */
    public AttendPunchTimeQuery getAttendPunchTimeQuery() {
        AttendPunchTimeQuery attendPunchTimeQuery = new AttendPunchTimeQuery();
        List<AttendPunchTimeDO> attendPunchTimeDOList = attendPunchTimeService.list(new AttendPunchTimeDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPunchTimeDOList)) {
            AttendPunchTimeDO attendPunchTimeDO = attendPunchTimeDOList.get(0);
            attendPunchTimeQuery = attendPunchTimeDO.to(AttendPunchTimeQuery.class);
            if (attendPunchTimeDO.getGmtCreate() != null) {
                attendPunchTimeQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPunchTimeDO.getGmtCreate(),-1));
                attendPunchTimeQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPunchTimeDO.getGmtCreate(),1));
            }
            if (attendPunchTimeDO.getGmtModified() != null) {
                attendPunchTimeQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPunchTimeDO.getGmtModified(),-1));
                attendPunchTimeQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPunchTimeDO.getGmtModified(),1));
            }
        }
        return attendPunchTimeQuery;
    }

    /**
     * 保存示例
     * @return AttendPunchTimeVO
     */
    public AttendPunchTimeVO saveAttendPunchTimeExample(){
        AttendPunchTimeAddDTO addDTO = this.getAttendPunchTimeAddDTO();
        AttendPunchTimeVO attendPunchTimeVO = attendPunchTimeService.save(addDTO,buildTokenUser());
        return attendPunchTimeVO;
    }


}

